package com.seo.textgen;

public class FilteredTextGenerator implements TextGenerator {

	private TextGenerator textGenerator;
	private SentenceFilter[] sentenceFilters;

	public FilteredTextGenerator(TextGenerator textGenerator, SentenceFilter... sentenceFilters) {
		this.textGenerator = textGenerator;
		this.sentenceFilters = sentenceFilters;
	}

	public String generateSentence() {
		while (true) {
			String sentence = textGenerator.generateSentence();
			if (isFilter(sentence)) {
				return sentence;
			}
		}
	}

	private boolean isFilter(String sentence) {
		for (SentenceFilter filter : sentenceFilters) {
			if (!filter.filter(sentence)) {
				return false;
			}
		}
		return true;
	}
}
